package cn.good.yan.w1;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


/**
 * 1 Web 操作页面
 * @author shengren.yan
 * @create 2023-10-01
 */
@Controller
public class Con1 {

    // 返回字符串
    @ResponseBody
    @RequestMapping("/sucsess")
    public String execute() {
        return "hello";
    }

    // 返回的是前端页面   @RequestMapping( {"/execute","/execute"} ) 可配置多个
//    @RequestMapping( {"/home","/index"} )
//    public String success(Map<String, Object> map) {
//        map.put("name", "good");
//        // classpath:/templates/list.html
//        return "user/list";
//        // 重定向
//        // return "redirect: /其他请求";
//    }

    // 转发 - 请求到 t2
    @GetMapping("/go/c1")
    public String t1(HttpServletRequest request){
        request.setAttribute("msg","成功");
        request.setAttribute("code",200);
        return "forward:/t2";
    }

    // 转发 - 请求到 t2
    @ResponseBody
    @RequestMapping("/t2")
    public Map<String, Object> t2(@RequestAttribute("msg") String msg, HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        map.put("从其他转发的参数msg,通过注解方式", msg);
        map.put("从其他转发的参数",  request.getAttribute("code"));
        return map;
    }

}
